package com.ys.chatserver.common.dto.cnst;

public class RetResult<T> {

    public int code;

    private String msg;

    private T data;

    public static <T> RetResult<T> successResult(String msg, T t) {
        RetResult<T> result = new RetResult<>();
        result.code = RetCode.SUCCESS.code;
        result.msg = msg;
        result.data = t;
        return result;
    }

    public static <T> RetResult<T> successResult(String msg) {
        RetResult<T> result = new RetResult<>();
        result.code = RetCode.SUCCESS.code;
        result.msg = msg;
        return result;
    }

    public static <T> RetResult<T> failResult(String msg, T t) {
        RetResult<T> result = new RetResult<>();
        result.code = RetCode.INTERNAL_SERVER_ERROR.code;
        result.msg = msg;
        result.data = t;
        return result;
    }


    public static <T> RetResult<T> failResult(String msg) {
        RetResult<T> result = new RetResult<>();
        result.code = RetCode.INTERNAL_SERVER_ERROR.code;
        result.msg = msg;
        return result;
    }

    public static <T> RetResult<T> failResult(String msg, int code) {
        RetResult<T> result = new RetResult<>();
        result.code = code;
        result.msg = msg;
        return result;
    }


    public RetResult<T> setCode(RetCode retCode) {
        this.code = retCode.code;
        return this;
    }

    public int getCode() {
        return code;
    }

    public RetResult<T> setCode(int code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public RetResult<T> setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public T getData() {
        return data;
    }

    public RetResult<T> setData(T data) {
        this.data = data;
        return this;
    }

}
